import game from "./game";

const { ccclass, property } = cc._decorator;

@ccclass
export default class bullet extends cc.Component {
    canvasHeight: cc.Node = null;
    airplaneNode: cc.Node = null;
    canvasHeightNode: number = null;
    airplanePosition: cc.Vec2 = null;

    onLoad() {
        this.canvasHeight = cc.find('Canvas');
        this.airplaneNode = cc.find('Canvas/飞机');
        this.canvasHeightNode = this.canvasHeight.height;


    }
    protected onEnable(): void {
        this.airplanePosition = this.airplaneNode.getPosition();
    }
    start() {
    }
    update(dt) {
        let speed: number = 6;
        this.airplanePosition.y += 12;
        this.node.setPosition(cc.v2(this.airplanePosition));
        let airy = this.airplanePosition.y;
        let cy = this.canvasHeightNode;

        if (airy > cy) {
            this.diss();
            return;
        }

    }
    diss() {
        // console.log("子弹飞出背景销毁")
        game.inst.destroyBullet(this.node);


    }

    onCollisionEnter(other: cc.Collider, self: cc.Collider) {
        // console.log("碰撞");
        this.diss();
    }

}
